using UnityEngine;
using UnityEngine.UI;

public class PrecisionBannerAnimator : MonoBehaviour
{
	private Transform bannerTransform;

	private Transform textTransform;

	private SpriteRenderer bannerSprite;

	private SpriteRenderer bannerShine;

	private SpriteRenderer bannerShineWhite;

	private Text mainTextComponent;

	private Text shadowTextComponent;

	[SerializeField]
	private string soundName;

	private void Awake()
	{
		DefineConnections();
		PrepareToAnimate();
	}

	private void DefineConnections()
	{
		bannerTransform = base.transform.FindDeepChild("BannerSprite");
		bannerSprite = bannerTransform.GetComponent<SpriteRenderer>();
		bannerShine = base.transform.FindDeepChild("BannerShine").GetComponent<SpriteRenderer>();
		bannerShineWhite = base.transform.FindDeepChild("BannerShineWhite").GetComponent<SpriteRenderer>();
		textTransform = base.transform.FindDeepChild("Text");
		mainTextComponent = textTransform.FindDeepChild("MainText").GetComponent<Text>();
		shadowTextComponent = textTransform.FindDeepChild("ShadowText").GetComponent<Text>();
	}

	private void PrepareToAnimate()
	{
		SetSpriteRendererAlpha(bannerSprite, 0f);
		SetSpriteRendererAlpha(bannerShine, 0f);
		SetSpriteRendererAlpha(bannerShineWhite, 0f);
		SetTextAlpha(mainTextComponent, 0f);
		SetTextAlpha(shadowTextComponent, 0f);
		bannerTransform.position = base.transform.position + Vector3.right * 0.7f;
		textTransform.position = base.transform.position + Vector3.left * 0.7f;
	}

	private void SetSpriteRendererAlpha(SpriteRenderer spriteRenderer, float alpha)
	{
		Color color = spriteRenderer.color;
		color.a = alpha;
		spriteRenderer.color = color;
	}

	private void SetTextAlpha(Text text, float alpha)
	{
		Color color = text.color;
		color.a = alpha;
		text.color = color;
	}

	public void AnimateBannerShow()
	{
		AudioController.instance.Play(soundName);
		GameObject gameObject = bannerTransform.gameObject;
		Vector3 position = base.transform.position;
		float y = position.y;
		Vector3 position2 = base.transform.position;
		iTween.MoveTo(gameObject, new Vector3(0f, y, position2.z), 0.53f);
		GameObject gameObject2 = textTransform.gameObject;
		Vector3 position3 = base.transform.position;
		float y2 = position3.y;
		Vector3 position4 = base.transform.position;
		iTween.MoveTo(gameObject2, new Vector3(0f, y2, position4.z), 0.53f);
		iTween.ValueTo(base.gameObject, iTween.Hash("from", 0f, "to", 1f, "onupdate", "BannerShowTween", "time", 0.25f));
		iTween.ValueTo(base.gameObject, iTween.Hash("from", 0f, "to", 1f, "onupdate", "ShineShowTween", "time", 0.1f, "delay", 0.05f));
		iTween.ValueTo(base.gameObject, iTween.Hash("from", 1f, "to", 0f, "onupdate", "ShineShowTween", "time", 0.5f, "delay", 0.15f));
	}

	public void AnimateBannerHide()
	{
		iTween.MoveTo(bannerTransform.gameObject, base.transform.position + Vector3.left * 0.35f, 1.5f);
		iTween.MoveTo(textTransform.gameObject, base.transform.position + Vector3.right * 0.35f, 1.5f);
		iTween.ValueTo(base.gameObject, iTween.Hash("from", 1f, "to", 0f, "onupdate", "BannerShowTween", "oncomplete", "DestroyAnimation", "time", 0.4f));
	}

	private void BannerShowTween(float value)
	{
		SetSpriteRendererAlpha(bannerSprite, value);
		SetTextAlpha(mainTextComponent, value);
		if (value > 0.9f)
		{
			SetTextAlpha(shadowTextComponent, (value / 1f - 0.9f) * 10f);
		}
		else
		{
			SetTextAlpha(shadowTextComponent, 0f);
		}
	}

	private void DestroyAnimation()
	{
		UnityEngine.Object.Destroy(base.gameObject);
	}

	private void ShineShowTween(float value)
	{
		SetSpriteRendererAlpha(bannerShine, value);
		SetSpriteRendererAlpha(bannerShineWhite, value);
	}
}
